import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-10-06
 * Time: 22:37
 */
public class Test103 {
    static List<String> ret;
    static StringBuilder path;
    static int n;
    static int left, right;
    public static List<String> generateParenthesis(int n1) {
        ret = new ArrayList<>();
        n = n1;
        path = new StringBuilder();
        dfs();
        return ret;
    }

    public static void dfs() {
        if(right == n) {
            ret.add(path.toString());
            return;
        }

        if(left < n) {
            path.append("(");
            left++;
            dfs();
            left--;
            path.deleteCharAt(path.length()-1);
        }
        if(right < left) {
            path.append(")");
            right++;
            dfs();
            right--;
            path.deleteCharAt(path.length()-1);
        }
    }

    public static void main(String[] args) {
        int m = 3;
        generateParenthesis(m);
        System.out.println(ret);
    }
}
